Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
    ''' <summary>
    ''' Controller class for Threads
    ''' </summary>
		<System.ComponentModel.DataObject()> Public Partial Class ThreadsController
    
        ' Preload our schema..
        Dim thisSchemaLoad As Threads = New Threads()
        Private strUserName As String = String.Empty
        Protected ReadOnly Property UserName() As String
            Get
				If strUserName.Length = 0 Then
		        
    				If Not System.Web.HttpContext.Current Is Nothing Then
						strUserName = System.Web.HttpContext.Current.User.Identity.Name
					Else
		        		strUserName = System.Threading.Thread.CurrentPrincipal.Identity.Name
					End If
					Return strUserName
				End If
				Return strUserName
			End Get
        End Property
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchAll() As ThreadsCollection
        
            Dim coll As ThreadsCollection = New ThreadsCollection()
            Dim qry As Query = New Query(Threads.Schema)
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
            
        End Function
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByID(ByVal Threadid As Object) As ThreadsCollection 
        
            Dim coll As ThreadsCollection = New ThreadsCollection().Where("threadid", Threadid).Load()
            Return coll
        
        End Function
        
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByQuery(ByVal qry As SubSonic.Query) As ThreadsCollection 
        
            Dim coll As ThreadsCollection = New ThreadsCollection()
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, True)> Public Function Delete(ByVal Threadid As Object) as Boolean
        
            Return (Threads.Delete(Threadid) = 1)
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, False)> Public Function Destroy(ByVal Threadid As Object) as Boolean
        
            Return (Threads.Destroy(Threadid) = 1)
        
        End Function
        
    	
	    ''' <summary>
	    ''' Inserts a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Insert, True)> Public Sub Insert(ByVal Locked As Boolean,ByVal Lastpostdate As Nullable(Of DateTime),ByVal Lastpostby As Nullable(Of Guid),ByVal Topicid As Integer,ByVal Views As Integer,ByVal Sticky As Boolean,ByVal Admin As Boolean)
	   
		    Dim item As Threads = New Threads()
		    
            item.Locked = Locked
            
            item.Lastpostdate = Lastpostdate
            
            item.Lastpostby = Lastpostby
            
            item.Topicid = Topicid
            
            item.Views = Views
            
            item.Sticky = Sticky
            
            item.Admin = Admin
            
	    
		    item.Save(UserName)
	   
	   End Sub
    	
	    ''' <summary>
	    ''' Updates a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Update, True)> Public Sub Update(ByVal Threadid As Integer,ByVal Locked As Boolean,ByVal Lastpostdate As Nullable(Of DateTime),ByVal Lastpostby As Nullable(Of Guid),ByVal Topicid As Integer,ByVal Views As Integer,ByVal Sticky As Boolean,ByVal Admin As Boolean)
	    
		    Dim item As Threads = New Threads()
		    
				item.Threadid = Threadid
				
				item.Locked = Locked
				
				item.Lastpostdate = Lastpostdate
				
				item.Lastpostby = Lastpostby
				
				item.Topicid = Topicid
				
				item.Views = Views
				
				item.Sticky = Sticky
				
				item.Admin = Admin
				
		    item.MarkOld()
		    item.Save(UserName)
	    
	    End Sub
    End Class
End Namespace
